<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="telephone=no" name="format-detection" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="https://m.mxzhuawawa.com/sega/src/css/style.css?__version=0.2">
    <title>推币机</title>
</head>
<body>
	<section class="pushcoin">
		<div class="video">
	      	<canvas id="video-canvas" class="video-canvas"></canvas>
	    </div>
	    <div class="control">
	    	<div class="title">当前游戏币</div>
            <div class="game_currency" id="game_currency"><span>0</span></div>
            <div class="title">当前积分</div>
            <div class="game_currency" id="game_currency_jf"><span>0</span></div>
            
            <!--
	    	<div class="title">上分</div>
	    	<div class="btn"><button class="addfractionn" onclick="upbetFn()">上分</button><button class="removefractionn" onclick="down_betFn()">清空分数</button></div>
            -->
            <div class="gobi">
    	    	<div class="title">投币数量</div>
    	    	<div class="btn"><button class="numbtn1" onclick="betinFn(1)">1个</button><button class="numbtn2" onclick="betinFn(2)">2个</button><button  class="numbtn3" onclick="betinFn(3)">3个</button></div>
            </div>
	    </div>
	</section>

	<script type="text/javascript" src="https://m.mxzhuawawa.com/sega/src/js/jquery-1.10.1.min.js?__version=0.1"></script>
	<script type="text/javascript" src="https://m.mxzhuawawa.com/sega/src/js/fastclick.js?__version=0.1"></script>
	<script type="text/javascript" src="https://m.mxzhuawawa.com/sega/src/js/jsmpeg.js?__version=0.1"></script>
    <script type="text/javascript" src="https://m.mxzhuawawa.com/src/js/md5.js"></script>
	<script type="text/javascript">
		var canvas = document.getElementById('video-canvas');
		var url = 'ws://118.126.111.240:8777/';
		//player = new JSMpeg.Player(url, {canvas: canvas,"streams":["tuibi_1","tuibi_2"],poster:"src/img/bg.jpg"});

		var pushSocketIO={
            _initConnect:function(){
                console.log('正在建立连接...');
                try{
                    msgsocket  =  new WebSocket('ws://58.43.196.139:9988');
                }catch(e){
                    console.log('连接异常 ： '+e);
                    return;
                }
                this._wbSocket = msgsocket;
                msgsocket.onopen = function(event) {
                    var data={};
                    data.cmd = "bind";
                    data.uid = "14043";
                    pushSocketIO._sendMsg(JSON.stringify(data));



                	var data={};
                    data.cmd = "login";
                    data.uid = "14043";
                    data.tuibi_id = "2";
                    data.sign = hex_md5("login"+"14043"+"2"+"mlb");

                    console.log("login"+"14043"+"2"+"mlb");

                    console.log(hex_md5("login"+"14043"+"2"+"mlb"));

                    pushSocketIO._sendMsg(JSON.stringify(data));

                    msgsocket.onmessage = pushSocketIO._msgReceive;

                    msgsocket.onclose = function(event) {
                        console.log('连接关闭.',event);
                    };

                    var data={};
                    data.cmd = "start_game";
                    data.uid = "14043";
                    data.tuibi_id = "2";
                    pushSocketIO._sendMsg(JSON.stringify(data));
                };
            },
            _sendMsg:function(msgBuf){
                if(msgBuf!=null&&msgBuf!='undefined'){
                    this._wbSocket.send(msgBuf);
                }else{
                    console.log('发送消息为空!');
                }
            },

            _msgReceive:function(event) {
                console.log(event.data);
                var data = JSON.parse(event.data);

                if(data.cmd=="user_coin"){
                    bet_resultFn(data.data)
                }
            }
        }
        pushSocketIO._initConnect();
        function betinFn(num){
        	console.log(num)
        	var data={};
                data.cmd = "betin";
                data.num = num;
				pushSocketIO._sendMsg(JSON.stringify(data));
        }
        function upbetFn(){
        	var data={};
                data.cmd = "up_bet";
                pushSocketIO._sendMsg(JSON.stringify(data));
        }
        function down_betFn(){
        	var data={};
                data.cmd = "down_bet";
                pushSocketIO._sendMsg(JSON.stringify(data));
        }
        /*
        var checktime=setInterval(function(){
        	check_betFn()
        },1000)*/
        function check_betFn(){
        	var data={};
                data.cmd = "check_bet";
                pushSocketIO._sendMsg(JSON.stringify(data));
        }
        function bet_resultFn(data){
            console.log(data);
        	$("#game_currency span").html(data.coin)

            $("#game_currency_jf span").html(data.bean)
        }
	</script>
</body>
</html>